package cn.ym.aircraft;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.util.Objects;

public class Images {
    protected static BufferedImage sky;
    protected static BufferedImage bullet;
    protected static BufferedImage[] heros;
    protected static BufferedImage[] airs;
    protected static BufferedImage[] bairs;
    protected static BufferedImage[] bees;

    protected static BufferedImage start;
    protected static BufferedImage pause;
    protected static BufferedImage gameover;


    static {
        Images.sky = loadImage("background.png");
        Images.bullet = loadImage("bullet.png");
        Images.heros = new BufferedImage[2];
        Images.heros[0] = loadImage("hero0.png");
        Images.heros[1] = loadImage("hero1.png");
        Images.airs = new BufferedImage[5];
        Images.airs[0] = loadImage("airplane.png");
        Images.bairs = new BufferedImage[5];
        Images.bairs[0] = loadImage("bigairplane.png");
        Images.bees = new BufferedImage[5];
        Images.bees[0] = loadImage("bee.png");
        for (int i = 1; i < airs.length; i++) {
            Images.airs[i] = loadImage("bom" + i + ".png");
            Images.bairs[i] = loadImage("bom" + i + ".png");
            Images.bees[i] = loadImage("bom" + i + ".png");
        }
        Images.start = loadImage("start.png");
        Images.pause = loadImage("pause.png");
        Images.gameover = loadImage("gameover.png");
    }

    public static BufferedImage loadImage(String fileName){
        try{
            return ImageIO.read(Objects.requireNonNull(FlyingObject.class.getResource(fileName)));
        }catch(Exception e){
            e.printStackTrace();
            throw new RuntimeException();
        }
    }

}
